<style lang="less">
@import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入用户名和密码登录</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import {mapActions} from 'vuex'
import {getAllStatus} from "@/api/data";
export default {
  components: {
    LoginForm
  },
  data(){
    return  {
      getAllStatus:getAllStatus
    }
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    handleSubmit({userName, passWord}) {
      this.handleLogin({userName, passWord}).then(res => {
        if (res.code === 200) {
          this.getUserInfo().then(res => {
            sessionStorage.removeItem("status");
            this.getAllStatus().then(
              o=>{
                if (o.data.code == 200){
                  localStorage.setItem("status",JSON.stringify(o.data.object));
                }else{
                  localStorage.setItem("status", {});
                }
              }
            );
            this.$router.push({
              name: this.$config.homeName
            })
          })
        } else {
          this.$Message.error(res.message);
        }
      })
    }
  }
}
</script>

<style>

</style>
